package com.magicsoft.app.adapter;

import java.util.List;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.boyuan.huijiaoyu.R;


public class IntroAdapter extends PagerAdapter {

	
	private List<Integer> data;
	private Context context;
	private LayoutInflater inflater;
	
	public  IntroAdapter(List<Integer> list,Context aContext) {
		data = list;
		context = aContext;
		inflater = LayoutInflater.from(context);
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return data.size();
	}

	@Override
	public boolean isViewFromObject(View arg0, Object arg1) {
		return arg0 == (View) arg1;
	}
	
	
	
	
	@Override
	public Object instantiateItem(final ViewGroup container, final int position) {

		View subView = (View)inflater.inflate(R.layout.intro_single, null);
		
		ImageView iv=(ImageView)subView.findViewById(R.id.imgIntro);
		
		iv.setImageResource(data.get(position));
		
		((ViewPager) container).addView(subView, 0);

		return subView;
	}

	@Override
	public void destroyItem(ViewGroup container, int position, Object object) {

		container.removeView((View) object);

//		View view = (View) object;
//		if (view != null) {
//			view = null;
//
//		}
	}
	

}
